<template>
  <el-dialog v-model="dialog.visible"
             width="100%"
             :title="dialog.title"
             :before-close="closeDialog">
    <basic-container>
      <avue-crud
          v-if="tableOption"
          v-bind="bindVal"
          v-on="onEvent">
        <template #menu="{type,size,row}">
          <el-button link icon="el-icon-edit" :size="size" @click="designForm(row)" :type="type">设计
          </el-button>
          <el-button link icon="el-icon-search" :size="size" @click="viewData(row)" :type="type">查看数据
          </el-button>
        </template>
      </avue-crud>
      <form-preview-data ref="formPreviewData"></form-preview-data>
      <start-form-design-dialog ref="startFormDesignDialog" @submit="refreshChange"></start-form-design-dialog>
    </basic-container>
  </el-dialog>
</template>

<script>

import {createDynamicMixin} from "@/mixins/startCrud.js";
import createMenu from "./createMenu.vue";
import createShare from "./createShare.vue";
import formApi from "../../../../api/start/formEngine/formApi";
import StartFormDesignDialog from "components/start-form-design/start-form-design-dialog.vue";
import FormPreviewData from "@/views/start/formEngine/form/formPreviewData.vue";
import FormPreviewTable from "components/form-design/formPreviewTable.vue";
import startSearchModel from "@/config/startSearchModel";

const mixinOption = {};
mixinOption.name = "start/formEngine/form";
mixinOption.list = "pageHistory"


export default {
  name: "formHistoryVersionDialog",
  mixins: [createDynamicMixin(mixinOption)],
  components: {FormPreviewTable, FormPreviewData, StartFormDesignDialog, createMenu, createShare},
  data() {
    return {
      dialog: {
        visible: false,
        title: "",
      },
      formCode: null,
    }
  },

  methods: {
    show(row) {
      this.formCode = row.formCode;
      this.dialog.title = "【" + row.formName + "】历史版本"
      this.restLoadList();
      this.dialog.visible = true;

    },
    loadCrudColumnBefore(column) {
      if (column.prop === 'tablePreVersion') {
        column.hide = true;
      }
    },
    beforeLoadDataSource(search) {
      search.start_search_formCode = this.formCode;
      search.start_search_deploymentStatus = startSearchModel.GT + 0;
    },
    loadCrudOptionAfter(formOption) {
      formOption.menuType = "button"
      formOption.addBtn = false;
      formOption.editBtn = false;
      formOption.delBtn = false;
    },
    beforeOpenAddDialog(form, done) {
      this.$refs.startFormDesignDialog.show(null)

    },
    designForm(row) {
      this.$refs.startFormDesignDialog.show(row.id)
    },
    viewData(row) {
      this.$refs.formPreviewData.show(row.id);
    },

    rowDblclick(row, column) {
      this.$refs.startTableCrud.rowEdit(row, row.$index)
    },

    syncDataBaseFrom(row) {
      this.$confirm(`此操作将可能导致【${row.name}】表单数据丢失！, 是否继续?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        return formApi.synchronizationTable(row.id)
      }).then(res => {
        this.$message({
          showClose: true,
          message: '同步成功',
          type: 'success'
        });
        this.loadRemoteDataSources()
      })
    },
    closeDialog() {
      this.dataSource = [];
      this.searchParams = {}
      this.dialog.visible = false;
    }
  }
}
</script>

<style scoped>

</style>
